#!/bin/bash
#################jdk源码安装##################
#http://www.oracle.com/technetwork/java/javase/downloads/index.html

#定义JDK安装包文件路径
jdkPackage=jdk-8u121-linux-x64
#定义JDK解压后的文件夹名字
jdkDir=jdk1.8.0_121
#定义安装目录
jdkPath=/usr/lib/

#卸载已经安装的openjdk
rpm -qa | grep jdk | xargs rpm -e --nodeps

mkdir -p ${jdkPath}
tar -zxvf ${jdkPackage}.tar.gz
cp -r ${jdkDir} ${jdkPath}

echo "
#set java environment
JAVA_HOME=${jdkPath}${jdkDir}
CLASSPATH=.:\$JAVA_HOME/jre/lib/ext:\$JAVA_HOME/lib/tools.jar
PATH=\$JAVA_HOME/bin:\$PATH
export JAVA_HOME CLASSPATH PATH
" >> /etc/profile
source /etc/profile

echo "javac version:"
javac -version
echo "java version:"
java -version

echo "
export JAVA_HOME=${jdkPath}${jdkDir}";

echo "source /etc/profile
"
echo "finish"
